package com.chhuang.ewcrm.utils;

import com.chhuang.ewcrm.string.StringUtil;
import javafx.scene.control.TextFormatter;
import org.apache.commons.lang3.StringUtils;

import java.util.function.UnaryOperator;

/**
 * @author chhuang
 * @create 2020-10-25-15:59
 */
public class IntTextFilter extends LengthTextFilter {

    public IntTextFilter(){}
    public IntTextFilter(int maxLength){
        this.maxLength = maxLength;
    }

    @Override
    public TextFormatter.Change apply(TextFormatter.Change change) {
        change = super.apply(change);
        if(change!=null) {
            String newText = change.getControlNewText();
            if ((StringUtils.isEmpty(newText) || StringUtil.isPositiveInteger(newText))) {
                return change;
            }
        }
        return null;
    }
}